/* ==================================
	Main
 ================================== */
package it.unibo.iss.domotica.system;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import it.unibo.contact.domoticaContact.DomoticaContactMain;
import it.unibo.iss.domotica.DomoticDomain;
import it.unibo.iss.domotica.edDomain.ISensor;
import it.unibo.iss.domotica.edDomain.Sensor;
import it.unibo.iss.domotica.EDDomain.Transmitter;

public class SysDomotichSensors extends DomoticaContactMain {

	private ArrayList<Transmitter> transmitters;
	
	// Logger
	private static final Logger logger = Logger.getLogger(SysDomotichSensors.class);

		
	@Override
	protected void configure() {
		logger.debug("--------- Start configuration ---------");
		
		try {
			configureTheSystem();
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.configure();
		
		logger.debug("--------- End configuration ---------");
	}

	private void configureTheSystem() throws Exception {
		transmitters = new ArrayList<Transmitter>();
			
		DomoticDomain domain = new DomoticDomain();
		for(ISensor sensor : domain.createSensors()) {
			Transmitter transmitter = new Transmitter(sensor);
			transmitter.setName("transmitter" + sensor.getEdName());
			transmitters.add(transmitter);
		}
		
////		String edName = "edIB0";
////		Sensor sensor = new Sensor(1, 500);
////		tx = new Transmitter(edName, sensor);
//		
//		logger.debug("Configuring trasmitters...");
//		
//		// Elettrodomestici Indispensabili Consumo Basso
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edIB" + i;
//			Sensor sensor = new Sensor(1, 500);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}
//
//		// Elettrodomestici Superflui Consumo Basso
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edSB" + i;
//			Sensor sensor = new Sensor(1, 500);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}
//
//		// Elettrodomestici Indispensabili Consumo Medio
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edIM" + i;
//			Sensor sensor = new Sensor(501, 1000);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}
//
//		// Elettrodomestici Superflui Consumo Medio
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edSM" + i;
//			Sensor sensor = new Sensor(501, 1000);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}
//
//		// Elettrodomestici Indispensabili Consumo Alto
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edIA" + i;
//			Sensor sensor = new Sensor(1001, 2000);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}
//
//		// Elettrodomestici Superflui Consumo Alto
//		for(int i = 0 ; i < 3 ; i++) {
//			String edName = "edSA" + i;
//			Sensor sensor = new Sensor(1001, 2000);
//			Transmitter transmitter = new Transmitter(edName, sensor);
//			transmitter.setName("transmitter" + edName);
//			transmitter.setEnv(env);
//			transmitters.add(transmitter);
//		}		
	}

	@Override
	protected void start(){
		logger.debug("Starting trasmitters...");
		
		for(Transmitter tx : transmitters) {
			tx.start();
		}
//		tx.start();
	}
	
	public static void main(String args[]) throws Exception {
		SysDomotichSensors system = new SysDomotichSensors( );
		system.doJob();
	}

}